import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDStrength {
	/**id，对应系统*/
	id,
	/**描述*/
	note,
	/**开启等级*/
	unlockLevel,
	/**优先级*/
	order,
	/**图标*/
	icon,
	/**跳转id*/
	jumpId,

	/**枚举数量*/
	EnumCount
}



export class CDStrength{
	/**id，对应系统*/
	public id: number;
	/**描述*/
	public note: number;
	/**开启等级*/
	public unlockLevel: number;
	/**优先级*/
	public order: number;
	/**图标*/
	public icon: string;
	/**跳转id*/
	public jumpId: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDStrength.id: return this.id;
			case E_CDStrength.note: return this.note;
			case E_CDStrength.unlockLevel: return this.unlockLevel;
			case E_CDStrength.order: return this.order;
			case E_CDStrength.icon: return this.icon;
			case E_CDStrength.jumpId: return this.jumpId;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDStrength.id: this.id = v; break;
			case E_CDStrength.note: this.note = v; break;
			case E_CDStrength.unlockLevel: this.unlockLevel = v; break;
			case E_CDStrength.order: this.order = v; break;
			case E_CDStrength.icon: this.icon = v; break;
			case E_CDStrength.jumpId: this.jumpId = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDStrength> = new HashMap<number, CDStrength>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDStrength[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDStrength();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].note = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].unlockLevel = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].order = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].jumpId = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDStrength{
		return this.datas ? this.datas.get(id) : null;
	}
}
